import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class FileSearch {
    public static void main(String[] args) {
        String folderPath = "C:\\Users\\ASUS\\Desktop\\慧科项目\\eks-backend\\eks-backend\\ai\\configmap"; // 文件夹路径
        String searchTerm = "http://"; // 要搜索的单词

        File folder = new File(folderPath);

        if (folder.isDirectory()) {
            File[] files = folder.listFiles();

            if (files != null) {
                for (File file : files) {
                    if (file.isFile()) {
                        searchInFile(file, searchTerm);
                    }
                }
            }
        }
    }

    public static void searchInFile(File file, String searchTerm) {
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            String line;
            int lineNum = 1;
            boolean found = false;

            while ((line = reader.readLine()) != null) {
                if (line.contains(searchTerm)) {
                    found = true;
                    System.out.println("File: " + file.getName() + " Line: " + lineNum + " - " + line);
                }
                lineNum++;
            }

            if (!found) {
                System.out.println("File: " + file.getName() + " - No matching lines found");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
